package com.bruce.tool.rpc.retry.strateties;

import com.github.rholder.retry.Attempt;
import com.github.rholder.retry.WaitStrategy;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author Bruce(刘正航)
 */
public class CustomWaitStrategy implements WaitStrategy {
    private List<Long> times;

    public CustomWaitStrategy(Long... times) {
        this.times = Lists.newArrayList(times);
    }

    @Override
    public long computeSleepTime(Attempt failedAttempt) {
        return times.get((int) failedAttempt.getAttemptNumber());
    }
}